package com.itheima.Server;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

public class Server {

    public static void main(String[] args) throws IOException {
        //创建集合存储连接成功的客户端的socket对象
        ArrayList<Socket> socketList = new ArrayList<>();
        //创建集合存储本地文件的用户信息
        ArrayList<String> userinfoList = new ArrayList<>();
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("sockethomework\\serverdir\\userinfo.txt")));
        String s;
        while ((s = br.readLine()) != null) {
            userinfoList.add(s);
        }
        br.close();
        //创建ServerSocket对象并指定端口号
        ServerSocket ss = new ServerSocket(8888);
        while (true) {
            //监听客户端的连接并返回一个Socket对象
            Socket socket = ss.accept();
            //添加到集合
            socketList.add(socket);
            //创建一个线程对象并启动
            new Thread(new MyRunable(socket,socketList,userinfoList)).start();
        }
    }
}
